//
//  StatusModelView.swift
//  weibo
//
//  Created by 陈经纬 on 16/7/26.
//  Copyright © 2016年 陈经纬. All rights reserved.
//

import Foundation
import UIKit

//模型视图,为了处理模型的业务逻辑
class StatusViewModel: NSObject{
    var statusModel:Status
    init(status:Status){
        self.statusModel = status
        
        //1.处理时间数据********************************************************
        
        // let time = "Tue Jul 25 10:46:07 +0800 2016"
        let time = status.created_at
        let timeDate = NSDate.creatDate(time!, formatter: "EE MM dd HH:mm:ss Z yyyy")
        
        createdStr = timeDate.descriptionStr()
        
        //2.微博来源********************************************************
        //<a href="http://weibo.com/" rel="nofollow">微博 weibo.com</a>
        //只需要截取"微博 weibo.com"
        if let str:NSString = status.source where status.source != ""{
            let strLoact = str.rangeOfString(">").location + 1
            let strLenth = str.rangeOfString("<", options: NSStringCompareOptions.BackwardsSearch).location - strLoact
            
            let strSource = str.substringWithRange(NSMakeRange( strLoact, strLenth))
            sourceStr = "来自" + strSource
        }
        
        // 3.设置头像
        
            
            iconURL = NSURL(string: status.user?.profile_image_url ?? "")
        

        
        //4.用户认证头像
        switch status.user?.verified_type ?? -1{
        case 0:
            profileImage  = UIImage(named:  "avatar_vip")
        case 2, 3, 5:
            profileImage = UIImage(named: "avatar_enterprise_vip")
        case 220:
            profileImage  = UIImage(named: "avatar_grassroot")
        default:
            
            profileImage = nil
        }

        
        //5微博会员图标
        if status.user?.mbrank >= 1 && status.user?.mbrank <= 6 {
            mbrankImage = UIImage(named: "common_icon_membership_level\(status.user?.mbrank)")
            //                    screen_name.textColor = UIColor.orangeColor()
        }


}
    
    
    
    //1.微博创建时间数据
    var createdStr:String?
    
    //2.微博来源真正需要的数据
    var sourceStr:String?
    
    ///3.用户头像
    var iconURL:NSURL?
    
    ///4. 用户认证头像
    var profileImage:UIImage?
    
    ///5. 会员图标
    var mbrankImage:UIImage? = nil
}